extends ../layout/admin

block head
  script(src="/webjars/ace/1.2.0/src-min/ace.js")
  script(src="/webjars/ace/1.2.0/src-min/theme-github.js")
  script(src="/webjars/ace/1.2.0/src-min/mode-markdown.js")
  
block content
  h1 Edit Post
  hr

  form.post-form(method="post",action="/admin/posts/#{post.getId()}")
    .item-row
      input(type="hidden", name='_csrf', value='#{_csrf.token}')
    .item-row
      input.form-control(type="text", name="title", value='#{postForm.getTitle()}')
    .item-row
      textarea.form-control#content(name="content", style="display:none;")
        = postForm.getContent()
      div#content-editor
        #{postForm.getContent()}
    .item-row
      hr
      .row
        .col-sm-3
          span Format
          select.form-control(name="postFormat")
            for format in postFormats
              if format != postForm.getPostFormat()
                option(value="#{format.getId()}") #{format.getDisplayName()}
              else 
                option(value="#{format.getId()}", selected="selected") #{format.getDisplayName()}
        .col-sm-3
          span Status
          select.form-control(name="postStatus")
            for status in postStatus
              if status != postForm.getPostStatus()
                option(value="#{status.getId()}") #{status.getName()}
              else 
                option(value="#{status.getId()}", selected="selected") #{status.getName()}
        .col-sm-3
          span Permalink
          input.form-control(name="permalink", value="#{postForm.getPermalink()}")
      
        .col-sm-3
          span Tags
          input.form-control(name="postTags", value="#{postForm.getPostTags()}")
    .item-row
      hr
      button.btn.btn-primary.btn-block(type="submit") Save

    script
      var editor = ace.edit("content-editor");
      editor.setTheme("ace/theme/github");

      var MarkdownMode = ace.require("ace/mode/markdown").Mode;
      editor.getSession().setMode(new MarkdownMode());

      editor.getSession().setUseWrapMode(true);

      $("form").submit(function(){
          $("#content").val(editor.getValue());
          return true;
      });

      //$(function() {
      //  var editor = new Simditor({
      //    textarea: $('#content'),
      //    markdown: true,
      //    toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent', 'alignment', '|', 'markdown']
      //    });
      //});

